<template>
    <div class="detail">
      <BHeader :back="true">详情页面</BHeader>
        <ul>
          <li>
            <label for="bookName">名字</label>
            <input type="text" v-model="book.bookName" id="bookName">
          </li>
          <li>
            <label for="bookInfo">信息</label>
            <input type="text" v-model="book.bookInfo" id="bookInfo">
          </li>
          <li>
            <label for="bookPrice">价格</label>
            <input type="text" v-model.number="book.bookPrice" id="bookPrice">
          </li>
          <button @click="updateData">修改</button>
        </ul>
    </div>
</template>

<script>
  import BHeader from '../base/BHeader.vue';
  import {getBook,updateBook} from '../api';
    export default {
      created(){
        this.getData();
      },
      methods:{
        async getData(){
          this.book = await getBook(this.bid);
          //如果获取的是空 返回列表页
          Object.keys(this.book).length>0?void 0:this.$router.push("/list");

          // this.book = await getBook(this.bid);
          // console.log(this.book);
        },
        async updateData(){
          await updateBook(this.bid,this.book);
          this.$router.push("/list")
        }
      },
        components:{
          BHeader
        },
        data() {
            return {
              book:{},
              msg: 'Welcome to Your Vue.js App'
            }
        },
      computed:{
          bid(){
            return this.$route.params.bid;//将路径参数的id映射到bid计算属性上，这样页面出可以简化一下
          }
      }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
  .detail{
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: #fff;
    z-index: 100;
    /*让详情页浮动到最上层*/
  }

  ul{
    margin:50px 10px 0 10px;
    li{
      label{
        display: block;
        font-size: 25px;
      }
      input{
        height: 25px;
        width: 100%;
        margin: 10px 0;
      }
    }
  }
  button{
    display: block;
    width: 60px;
    height: 25px;
    background: lightskyblue;
    color: #FFF;
    border: none;
    border-radius: 5px;
    outline: none;
    color: #2a2a2a;
    line-height: 25px;
  }
</style>
